package com.dys.hejiayuncommunity.system.domain;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.dys.hejiayuncommunity.common.core.domain.BaseEntity;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.Arrays;

/**
 * @Author: 疾风
 * @ClassName: SysRole
 * @Description: 角色实体
 * @CreateDate: 2024/12/23
 * @Version: v1.0.0
 */
@TableName(value = "sys_role")
public class SysRole extends BaseEntity {
    private static final long serialVersionUID = 1L;
    @Excel(name = "角色序号")
    @TableId
    private Long roleId;
    @Excel(name = "角色名称")
    private String roleName;
    @Excel(name = "角色权限")
    private String roleKey;
    @Excel(name = "角色排序")
    private Integer roleSort;
    @Excel(name = "数据范围", replace = {"所有数据权限_1", "自定义数据权限_2", "本部门数据权限_3", "本部门及以下数据权限_4"})
    private String dataScope;
    /**
     * 菜单树选择项是否关联显示(0:父子不互相关联显示,1:父子互相关联显示)
     */
    private boolean menuCheckStrictly;
    /**
     * 部门树选择项是否关联显示(0:父子不互相关联显示,1:父子互相关联显示)
     */
    private boolean deptCheckStrictly;
    @Excel(name = "角色状态", replace = {"正常_0", "停用_1"})
    private String status;
    /**
     * 删除标志：0:存在 2:删除
     */
    private String delFlag;

    /**
     * 用户是否存在此角色标识 ? 默认不存在
     */
    private boolean flag = false;

    /**
     * 菜单组
     */
    private Long[] menuIds;

    /**
     * 部门组,数据权限
     */
    private Long[] deptIds;

    /**
     * 判断当前角色是否为admin
     *
     * @return true: admin false: 非admin
     */
    public boolean isAdmin() {
        return isAdmin(this.roleId);
    }

    /**
     * 根据角色编号判断当前角色是否为管理员角色
     *
     * @param roleId 角色编号
     * @return true: admin, false: 非admin
     */
    public static boolean isAdmin(Long roleId) {
        return roleId != null && roleId == 1L;
    }

    public SysRole() {
    }

    public SysRole(Long roleId) {
        this.roleId = roleId;
    }

    public SysRole(Long roleId, String roleName, String roleKey, Integer roleSort, String dataScope, boolean menuCheckStrictly, boolean deptCheckStrictly, String status, String delFlag, boolean flag, Long[] menuIds, Long[] deptIds) {
        this.roleId = roleId;
        this.roleName = roleName;
        this.roleKey = roleKey;
        this.roleSort = roleSort;
        this.dataScope = dataScope;
        this.menuCheckStrictly = menuCheckStrictly;
        this.deptCheckStrictly = deptCheckStrictly;
        this.status = status;
        this.delFlag = delFlag;
        this.flag = flag;
        this.menuIds = menuIds;
        this.deptIds = deptIds;
    }

    public Long getRoleId() {
        return roleId;
    }

    public void setRoleId(Long roleId) {
        this.roleId = roleId;
    }

    @NotBlank(message = "角色名称必填")
    @Size(min = 0, max = 30, message = "角色名称长度不能超过30个字符")
    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    @NotBlank(message = "角色名称必填")
    @Size(min = 0, max = 100, message = "角色名称长度不能超过100个字符")
    public String getRoleKey() {
        return roleKey;
    }

    public void setRoleKey(String roleKey) {
        this.roleKey = roleKey;
    }

    public Integer getRoleSort() {
        return roleSort;
    }

    public void setRoleSort(Integer roleSort) {
        this.roleSort = roleSort;
    }

    public String getDataScope() {
        return dataScope;
    }

    public void setDataScope(String dataScope) {
        this.dataScope = dataScope;
    }

    public boolean isMenuCheckStrictly() {
        return menuCheckStrictly;
    }

    public void setMenuCheckStrictly(boolean menuCheckStrictly) {
        this.menuCheckStrictly = menuCheckStrictly;
    }

    public boolean isDeptCheckStrictly() {
        return deptCheckStrictly;
    }

    public void setDeptCheckStrictly(boolean deptCheckStrictly) {
        this.deptCheckStrictly = deptCheckStrictly;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getDelFlag() {
        return delFlag;
    }

    public void setDelFlag(String delFlag) {
        this.delFlag = delFlag;
    }

    public boolean isFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public Long[] getMenuIds() {
        return menuIds;
    }

    public void setMenuIds(Long[] menuIds) {
        this.menuIds = menuIds;
    }

    public Long[] getDeptIds() {
        return deptIds;
    }

    public void setDeptIds(Long[] deptIds) {
        this.deptIds = deptIds;
    }

    @Override
    public String toString() {
        return "SysRole{" +
                "roleId=" + roleId +
                ", roleName='" + roleName + '\'' +
                ", roleKey='" + roleKey + '\'' +
                ", roleSort=" + roleSort +
                ", dataScope='" + dataScope + '\'' +
                ", menuCheckStrictly=" + menuCheckStrictly +
                ", deptCheckStrictly=" + deptCheckStrictly +
                ", status='" + status + '\'' +
                ", delFlag='" + delFlag + '\'' +
                ", flag=" + flag +
                ", menuIds=" + Arrays.toString(menuIds) +
                ", deptIds=" + Arrays.toString(deptIds) +
                '}';
    }
}
